import java.security.spec.RSAOtherPrimeInfo;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class CardList {
    private static final String[] SORT = {"♣","♦","♥","♠"};
    public static List<PlayingCard> buyCards(){
        List<PlayingCard> list = new ArrayList<>();
        for (int i = 0; i < SORT.length; i++) {
            for (int j = 1; j <= 13; j++) {
                PlayingCard card = new PlayingCard(SORT[i],j);
                list.add(card);
            }
        }
        return list;

    }
    //交换
    public static void Swap(List<PlayingCard> list,int i,int j){
        PlayingCard card = list.get(i);
        list.set(i,list.get(j));
        list.set(j,card);
    }
    public static void shuffle(List<PlayingCard> list){
        Random random = new Random();
        //从后向左一次遍历，随机选一个位置与当前位置换位
        for (int i = list.size()-1; i > 0 ; i--) {
            int ret = random.nextInt(i);
            Swap(list,i,ret);
        }
    }
    public static List<List<PlayingCard>> DealCards(List<PlayingCard> list){
        //存放玩家
        List<List<PlayingCard>> list1 = new ArrayList<>();
        //一号玩家
        List<PlayingCard> list2 = new ArrayList<>();
        list1.add(list2);
        //二号玩家
        List<PlayingCard> list3 = new ArrayList<>();
        list1.add(list3);
        //三号玩家
        List<PlayingCard> list4 = new ArrayList<>();
        list1.add(list4);
        //发牌
        for (int i = 0; i < list1.size(); i++) {
            for (int j = 0; j < 13; j++) {
                list1.get(i).add(list.get(j));
                list.remove(0);
            }
        }
        return list1;

    }

    public static void main(String[] args) {
        List<PlayingCard> list = buyCards();//买牌
        shuffle(list);//洗牌
        List<List<PlayingCard>> list1 = DealCards(list);//发牌
//打印
        for (int i = 0; i < list1.size(); i++) {
            for (int j = 0; j < 13; j++) {
                System.out.print(list1.get(i).get(j) + " ");
            }
            System.out.println();
        }


    }
}
